<template>
  <el-scrollbar style="height: 100%" class="animated">
    <el-container class="main animated">
      <el-header class="header">
        <el-row>
          <el-col :xs="0" :sm="1" :md="2" :lg="4" :xl="6">
          </el-col>
          <el-col :xs="24" :sm="22" :md="20" :lg="16" :xl="12">
            <div class="header-top">
              <div class="logo">
                <a href="/" title="悟空VIP视频全网解析-vip视频在线解析">
                  <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"
                       viewBox="0 0 170.000000 90.000000"
                       preserveAspectRatio="xMidYMid meet" color-interpolation-filters="sRGB" class="el-tooltip"
                       style="margin: auto;">
                    <g fill="#e50012" transform="translate(0,25)">
                      <g>
                        <path
                            d="M5.69-34.85L9.94-34.85L9.94-25.94L11.23-25.94L11.23-38.25L15.48-38.25L15.48-25.94L16.74-25.94L16.74-22.54L15.48-22.54L15.48 0L11.23 0L11.23-22.54L9.94-22.54L9.94-8.28Q9.94-5.54 8.57-3.40L8.57-3.40L4.25-3.40Q5.69-5.58 5.69-8.28L5.69-8.28L5.69-22.54L5.69-25.94L5.69-34.85ZM34 0L23.13 0Q21.03 0 19.53-1.50Q18.03-2.99 18.03-5.10L18.03-5.10L18.03-12.34L18.03-15.74L22.28-15.74L34-15.74L38.25-15.74L38.25-12.34L38.25 0L36.73 0L34 0ZM34-12.34L22.28-12.34L22.28-3.40L34-3.40L34-12.34ZM21.18-31.45L21.77-34.85L18.03-34.85L18.03-38.25L38.25-38.25L38.25-34.85L26.02-34.85L25.43-31.45L32.78-31.45L35.48-31.45L37.03-31.45L37.03-21.25L38.29-21.25L38.29-17.85L37.03-17.85L32.78-17.85L18.07-17.85L18.07-21.25L19.33-21.25L20.58-28.05L18.07-28.05L18.07-31.45L21.18-31.45ZM24.76-28.05L23.54-21.25L32.74-21.25L32.74-28.05L24.76-28.05ZM46.75-31.41L46.75-34.81L62.27-34.81L60.31-38.21L65.23-38.21L67.19-34.81L80.75-34.81L80.75-31.41L80.75-28.05L76.50-28.05L76.50-31.41L51-31.41L51-28.05L46.75-28.05L46.75-31.41ZM46.75 0L46.75-3.36L61.61-3.36L61.61-18.40L46.75-18.40L46.75-21.80L80.75-21.80L80.75-18.40L65.89-18.40L65.89-3.36L80.75-3.36L80.75 0L46.75 0ZM74.06-29.31L78.64-23.10L73.73-23.10L69.15-29.31L74.06-29.31ZM53.44-23.10L48.56-23.10L53.14-29.31L58.02-29.31L53.44-23.10ZM89.25-25.94L89.25-29.34L93.50-29.34L96.23-29.34L100.48-29.34L101.22-29.34L103.18-32.74L89.21-32.74L89.21-36.14L90.43-38.25L94.68-38.25L93.46-36.14L107.43-36.14L107.43-32.74L105.47-29.34L107.43-29.34L107.43-28.05L107.43-25.94L107.43-4.88Q107.43-2.14 106.07 0L106.07 0L101.74 0Q103.18-2.18 103.18-4.88L103.18-4.88L103.18-7.87L100.48-7.87L100.48 0L96.23 0L96.23-7.87L93.50-7.87L93.50-11.27L96.23-11.27L96.23-17.04L93.50-17.04L93.50-20.44L96.23-20.44L96.23-25.94L93.50-25.94L93.50 0L89.25 0L89.25-25.94ZM113.01-25.94L108.76-25.94L110.72-34.85L108.76-34.85L108.76-38.25L119-38.25L123.25-38.25L123.25-34.85L123.25-30.82Q123.25-28.09 121.88-25.94L121.88-25.94L117.56-25.94Q119-28.12 119-30.82L119-30.82L119-34.85L114.97-34.85L113.01-25.94ZM118.15 0L113.90 0L113.90-7.87L108.76-7.87L108.76-11.27L113.90-11.27L113.90-17.85L108.76-17.85L108.76-21.25L109.65-24.65L112.64-24.65L111.72-21.25L113.90-21.25L113.90-24.65L118.15-24.65L118.15-21.25L123.29-21.25L123.29-17.85L118.15-17.85L118.15-11.27L123.29-11.27L123.29-7.87L118.15-7.87L118.15 0ZM100.52-17.04L100.52-11.27L103.22-11.27L103.22-17.04L100.52-17.04ZM100.52-25.94L100.52-20.44L103.22-20.44L103.22-25.94L100.52-25.94ZM151.78-33.26L151.78-23.36L165.75-23.36L165.75-19.96L164.46-19.96L164.46 0L160.24 0L160.24-19.96L151.78-19.96L151.78-4.88Q151.78-2.14 150.41 0L150.41 0L146.09 0Q147.53-2.18 147.53-4.88L147.53-4.88L147.53-19.96L147.53-23.36L147.53-32.74L147.53-34.85L147.53-36.14L164.46-38.25L164.46-34.85L151.78-33.26ZM137.26-38.25L140.66-38.25L140.66-34.85L146.24-34.85L146.24-31.45L140.66-31.45L140.66 0L137.26 0L137.26-31.45L131.71-31.45L131.71-34.85L137.26-34.85L137.26-38.25ZM133.19-29.34L136.59-29.34L136.59-7.02Q136.59-4.29 135.22-2.14L135.22-2.14L131.75-2.14Q133.19-4.32 133.19-7.02L133.19-7.02L133.19-29.34ZM141.36-7.02L141.36-29.34L144.76-29.34L144.76-7.02Q144.76-4.32 146.20-2.14L146.20-2.14L142.73-2.14Q141.36-4.29 141.36-7.02L141.36-7.02Z"
                            transform="translate(-4.25, 38.25)"></path>
                      </g>
                    </g>
                  </svg>
                </a>
              </div>
              <div class="tips">
                <span>{{ video.tips }}</span>
              </div>
            </div>
          </el-col>
          <el-col :xs="0" :sm="1" :md="2" :lg="4" :xl="6">
          </el-col>
        </el-row>
      </el-header>
      <el-main class="one-section animated">
        <el-row>
          <el-col :xs="0" :sm="1" :md="2" :lg="4" :xl="6">
          </el-col>
          <el-col :xs="24" :sm="22" :md="20" :lg="16" :xl="12">
            <div class="main-head">
              <div class="main-head-left">
                <el-select v-model="video.vip" placeholder="请选择">
                  <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    <span style="float: left">{{ item.label }}</span>
                  </el-option>
                </el-select>
              </div>
              <div class="main-head-center">
                <el-input autocomplete="off" type="text" @dblclick="dbClick($event)" v-model="video.url"
                          placeholder="请输入视频播放地址" clearable></el-input>
                <el-popover
                    placement="bottom"
                    :width="200"
                    trigger="click"
                >
                  <template #reference>
                    <span class="iconfont icon-ico parse" id="parse" title="创建此页面的OR码"></span>
                  </template>
                  <div style="width: 200px">
                    <vue-qr
                        :text="`${video.base}?url=${video.url}`"
                        :correctLevel="1"
                        :margin="6"
                        colorDark="#000"
                        colorLight="#fff"
                        :size="200"
                    ></vue-qr>
                  </div>
                </el-popover>
                <el-popover
                    class="history-pop"
                    placement="bottom-end"
                    :width="200"
                    trigger="click"
                >
                  <template #reference>
                    <span @click="viewHistory" class="iconfont icon-lishijilu history" id="history"
                          title="历史观看记录"></span>
                  </template>
                  <div style="width: 200px">
                    <p class="history-p" v-if="history.length>0" v-for="item in history.slice(0,5)">
                      <span @click="historyView(item)" class="txt"
                            style="padding-right: 5px;display: block;">{{ item.url }}</span>
                      <span @click="delHistory(item)" class="iconfont icon-guanbi close" title="删除历史"></span>
                    </p>
                    <p style="margin: 0;padding: 0" v-else>暂无历史记录</p>
                  </div>
                </el-popover>
              </div>
              <div class="main-head-right">
                <el-button v-if="video.playUrl" type="primary" @click="playVideo">重新播放</el-button>
                <el-button v-else type="primary" @click="playVideo">立即播放</el-button>
              </div>
            </div>
            <div class="main-body">
              <div id="main-video" class="main-video" :style="{height: video.height+'px'}">
                <template v-if="video.isPlay">
                  <iframe id="videobody" ref="videobody" width="100%" height="100%" allowfullscreen="true"
                          allowtransparency="true" frameborder="0" scrolling="no"
                          :src="video.playUrl"></iframe>
                </template>
              </div>
            </div>
          </el-col>
          <el-col :xs="0" :sm="1" :md="2" :lg="4" :xl="6">
          </el-col>
        </el-row>
      </el-main>
      <el-footer class="one-section animated">
        <el-row>
          <el-col :xs="0" :sm="1" :md="2" :lg="4" :xl="6">
          </el-col>
          <el-col :xs="24" :sm="22" :md="20" :lg="16" :xl="12">
            <el-alert
                title="本站视频源于互联网视频网站，系互联网抓取所得，仅供学习交流。已支持以下网站视频播放(包含VIP电影)"
                :closable="false"
                center
                type="success">
            </el-alert>
            <el-row style="margin-top: 10px;margin-bottom: 30px">
              <el-col style="text-align: center;margin-top: 6px;" :xs="8" :sm="8" :md="8" :lg="4" :xl="4"
                      v-for="item in videoListImg">
                <a :href="item.url" target="_blank">
                  <el-image :src="item.ico" fit="contain" style="height: 40px;padding: 0 10px"></el-image>
                </a>
              </el-col>
            </el-row>
          </el-col>
          <el-col :xs="0" :sm="1" :md="2" :lg="4" :xl="6">
          </el-col>
        </el-row>
      </el-footer>
    </el-container>
  </el-scrollbar>
</template>

<script>
import vueQr from 'vue-qr/src/packages/vue-qr.vue'
import axios from 'axios'

export default {
  name: "index",
  components: {
    vueQr
  },
  data() {
    return {
      video: {
        tips: "本站将持久更新最新可用解析接口，保证可用性！请持续关注... 若播放异常，刷新，更换接口尝试即可！",
        base: window.location.href.split("?")[0],
        url: "",
        vip: "",
        playUrl: "",
        height: 100,
        isPlay: false
      },
      history: [],
      options: [{
        value: 'https://jx.147g.cc/?url=',
        label: '全网智能解析（专线1）'
      }, {
        value: 'https://z1.m1907.cn/?a=1&jx=',
        label: '全网智能解析（专线2）'
      }, {
        value: 'https://jx.sigujx.com/?url=',
        label: '全网智能解析（专线3）'
      }, {
        value: 'https://jx.ivito.cn/?url=',
        label: '备用1'
      }, {
        value: 'http://jiexi.380k.com/?url=',
        label: '备用2'
      }, {
        value: 'https://www.8090g.cn/jiexi/?url=',
        label: '备用3'
      }],
      videoListImg: [
        {
          url: "https://www.iqiyi.com/",
          ico: "/img/iqiyi.png"
        },
        {
          url: "https://v.qq.com/",
          ico: "/img/tx.png"
        },
        {
          url: "https://www.youku.com/",
          ico: "/img/youku.png"
        },
        {
          url: "http://www.yinyuetai.com/",
          ico: "/img/yinyuetai.png"
        },
        {
          url: "https://www.bilibili.com/",
          ico: "/img/bilibili.png"
        },
        {
          url: "https://tv.sohu.com/",
          ico: "/img/sohu.png"
        }
      ]
    }
  },
  async mounted() {
    await this.loadVipList();
    let dom = document.getElementById("main-video")
    let that = this
    window.onresize = function () {
      let width = getStyle(dom, 'width');
      let height = getStyle(dom, 'height');
      if (width) {
        width = width.replace("px", "");
        if (width > 768) {
          that.video.height = ((parseInt(width) * 9) / 16) - 50;
        } else {
          that.video.height = ((parseInt(width) * 9) / 16);
        }
      }
    }

    function getStyle(ele, attr) {
      if (window.getComputedStyle) {
        return window.getComputedStyle(ele, null)[attr];
      }
      return ele.currentStyle[attr];
    }

    //resize
    window.onresize();
    this.video.vip = this.options[0].value;
    this.init();
  },
  methods: {
    async loadVipList() {
      await axios.get('./data/config.json')
          .then(resp => {
            if (resp.data.vip) {
              this.options = resp.data.vip
            }
            if (resp.data.tips) {
              this.video.tips = resp.data.tips
            }
          })
    },
    init() {
      if (this.$route.query) {
        let url = this.$route.query.url;
        if (url) {
          this.video.url = url;
          this.playVideo()
        }
      }
    },
    playVideo() {
      if (this.video.vip && this.video.url) {
        this.video.isPlay = true
        this.video.playUrl = ""
        setTimeout(() => {
          this.video.playUrl = this.video.vip + this.video.url
        }, 100)
        //store history
        let historyData = [];
        if (localStorage.getItem("history")) {
          historyData = JSON.parse(localStorage.getItem("history"))
        }
        if (historyData.length > 0) {
          if (historyData[0].url !== this.video.url) {
            historyData.push({
              url: this.video.url
            })
          }
        } else {
          historyData.push({
            url: this.video.url
          })
        }
        if (historyData.length > 10) {
          historyData = historyData.slice(0, 10)
        }
        localStorage.setItem("history", JSON.stringify(historyData))
      } else {
        this.$message.warning("请输入播放路径~ ")
      }
    },
    viewHistory() {
      if (localStorage.getItem("history")) {
        this.history = JSON.parse(localStorage.getItem("history"))
      }
    },
    historyView(item) {
      this.video.url = item.url
    },
    delHistory(item) {
      if (localStorage.getItem("history")) {
        let tempHistory = JSON.parse(localStorage.getItem("history"))
        for (let i = 0; i < tempHistory.length; i++) {
          if (item.url === tempHistory[i].url) {
            tempHistory.splice(i, 1)
            break;
          }
        }
        localStorage.setItem("history", JSON.stringify(tempHistory))
        this.history = tempHistory
      }
    },
    dbClick(e) {
      e.currentTarget.select();
    }
  }
}
</script>


<style lang="scss">
#app {
  height: 100vh;
}

input, button, select {
  outline: none;
}

.main-head {
  .main-head-center {
    .el-input {
      .el-input__inner {
        padding-right: 70px;
      }

      .el-input__suffix {
        margin-right: 40px !important;
      }
    }
  }
}

.el-message {
  padding: 10px 10px 10px 15px;
  min-width: auto !important;
  width: auto !important;
}

</style>

<style scoped lang="scss">

@import "../styles/element-variables";

$--color-primary-light-10: mix($--color-white, $--color-primary, 95%) !default;

.one-section {
  padding: 0 !important;
  padding-top: 15px !important;
}

.header {
  height: 60px;
  border-bottom: 1px solid #ececec;

  .header-top {
    display: flex;
    flex-direction: row;

    .logo {
      width: 110px;
      text-align: center;
      position: relative;
      margin-left: 5px;
    }

    .tips {
      height: 60px;
      line-height: 60px;
      color: #FE8B1F;
      font-size: 12px;
      margin-left: 10px;
    }
  }
}

@media screen and (max-width: 768px) {
  .parse {
    display: none;
  }

  .main-head {
    .main-head-center {
      .el-input {
        .el-input__inner {
          padding-right: 50px;
        }

        .el-input__suffix {
          margin-right: 20px !important;
        }
      }
    }
  }
}


.history-p {
  padding: 4px 0;
  margin: 0;
  cursor: pointer;
  position: relative;

  .txt:hover {
    color: rgba(255, 51, 51, 0.8);
  }

  .close {
    position: absolute;
    top: 50%;
    right: -12px;
    transform: translate(0, -50%);

    &:hover {
      color: rgba(255, 51, 51, 0.8);
    }
  }
}

.main-head {
  display: flex;
  flex-direction: row;

  .main-head-left {
    width: 200px;
  }

  .main-head-center {
    width: calc(100% - 300px);
    box-sizing: border-box;
    margin: 0 10px 0 8px;
    position: relative;

    .parse {
      cursor: pointer;
      position: absolute;
      top: 0;
      right: 28px;
      width: 20px;
      height: 40px;
      line-height: 40px;
      color: $--color-primary-light-5;
    }

    .history {
      cursor: pointer;
      position: absolute;
      top: 0;
      right: 6px;
      width: 20px;
      height: 40px;
      line-height: 40px;
      color: $--color-primary-light-5;
      font-size: 19px;
    }
  }

  .main-head-right {

  }
}

.main-body {
  .main-video {
    margin-top: 15px;
    height: 500px;
    background-color: $--color-primary-light-10;
    border-radius: 2px;
    position: relative;
  }
}

@media (max-width: 767px) {
  .header {
    height: auto !important;

    .header-top {
      display: flex;
      flex-direction: column;

      .logo {
        width: 120px;
        text-align: center;
        position: relative;
        margin: 0 auto;
      }

      .tips {
        height: auto !important;
        text-align: center;
        line-height: 20px;
        color: #FE8B1F;
        font-size: 12px;
        margin: 0;
        position: relative;
        top: -6px;
      }
    }
  }

  .main-head {
    padding: 0 10px;
    display: flex;
    flex-direction: column;

    .main-head-left {
      width: 100%;

      .el-select {
        width: 100% !important;
      }

      margin-bottom: 6px;
    }

    .main-head-center {
      margin-left: 0;
      width: 100%;
      margin-bottom: 6px;
    }

    .main-head-right {
      .el-button {
        width: 100% !important;
      }
    }
  }

}
</style>
